export default class RegisterForm {
    constructor(element, option){
        this.$element = $(element);
        this.$checkboxProtocol = this.$element.find('.checkbox-protocol');
        this.$btnSubmit = this.$element.find('.btn-submit');
        this.validateForm = null;
        this.init();
    }

    init(){
        this.validateForm = this.getValidateForm();
        this.handleChangeProtocol();
    }

    getValidateForm() {
        const $element = this.$element;
        return this.$element.validate({
            submitHandler: function (valid) {
                if (valid) {
                    $element.submit()
                }
                return false
            },
            rules: {
                name: {
                    required: true
                },
                password: {
                    required: true
                },
                mobile: {
                    required: true
                },
                code: {
                    required: true
                }
            },
            messages: {
                name: {
                    required: '请输入用户名/密码/邮箱'
                },
                password: {
                    required: '请输入密码'
                },
                mobile: {
                    required: '请填写手机号码'
                },
                code: {
                    required: '请填写验证码'
                }
            }
        })
    }


    handleChangeProtocol(){
        this.$checkboxProtocol.on('change', (e)=>{
            this.$btnSubmit.prop('disabled', !this.$checkboxProtocol.prop('checked'))
        })
    }
}